home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / NewsTicker.sit / NewsTicker / source code / WindowStuff / jGNEEngineCodeResource.a next >
Text File  |  1997-02-17  |  6KB  |  217 lines

  1.  
  2. ;    $Workfile:   jGNEEngineCodeResource.a  $
  3. ;    $Revision:   1.0  $
  4.  
  5. ;    This installs a 68k code block, hooks it into the GetNextEvent filter
  6. ;    routines, and sets up a Gestalt mechanism that can get called.  This allows
  7. ;    applications to enter and remove filters safely
  8.  
  9. ;    © 1996 CE Software, Inc.  All rights reserved.
  10.  
  11. ;    WHEN    WHO        WHAT
  12.  
  13.  
  14.  
  15.             BLANKS        ON
  16.             STRING        ASIS
  17.             PRINT    OFF
  18.                 INCLUDE     'Traps.a'
  19.                 INCLUDE     'ToolEqu.a'
  20.                 INCLUDE     'QuickEqu.a'
  21.                 INCLUDE     'SysEqu.a'
  22.                 INCLUDE        'ATalkEqu.a'
  23.                 INCLUDE        'PackMacs.a'
  24.                 include     'ShutdownEqu.a'
  25.                 include     'ScriptEqu.a'
  26.                 include        'StandardFile.a'
  27.                 include        'Processes.a'
  28.             PRINT    ON
  29. ;
  30. ;    Gestalt of type 'jGNE' will return the pointer to a routine that installs or
  31. ;    removes an entry in the table.
  32. ;
  33. ;    pascal void RegisterMe(short theAction, procptr theproc);
  34. ;        1, Register.  Add an entry to the table with procptr, also keeping the processserialnumber
  35. ;        2, Dispose.  Remove any entry with the current process, theproc is ignored
  36. ;
  37. ;
  38. ; We keep a table of entries within ourselves
  39. ;
  40. TblProc    equ    0            ;pointer to the routine to call, 0 means empty entry
  41. TblRef    equ    TblProc+4    ;a data pointer we keep for the routine's use
  42. TblPSN    equ    TblRef+4    ;Store the process serial number so we can check when the app crashes
  43. TblSize    equ    TblPSN+8
  44. TblMax    equ    10            ;number of entries in the table
  45. TblSpace    equ    TblMax*TblSize
  46.  
  47. jGNEEngineStuff        main    export
  48. ;
  49. ;    This installs our hooks into the GNEFilter and registers us with Gestalt.
  50. ;
  51. StartOfCode
  52.         move.l    #'jGNE',D0
  53.         lea        TheInstallProc,a1
  54.         _Gestalt
  55.         tst.w    D0
  56.         beq.s    @DoneHookup        ;if no error, we're already installed somewhere else
  57.         
  58.         lea        StartOfCode,A0    ;We need to survive forever.  Get the handle to ourselves.
  59.         _RecoverHandle
  60.         move.l    A0,-(SP)        ;put the handle on the stack twice
  61.         _Hlock                    ;and lock us down
  62.         _DetachResource            ;make us hang around.
  63.  
  64.         lea        OldHook,A0            ;hook us into GNEFilter
  65.         move.l    jGNEFilter,(A0)
  66.         lea        myGNEFilter,A0
  67.         move.l    A0,jGNEFilter
  68.         
  69.         move.l    #'jGNE',D0            ;register us so others can find us
  70.         LEA    MyGestaltHandler,A0
  71.         _NewGestalt
  72.  
  73. @DoneHookup
  74.         rts
  75. ;
  76. ;
  77. ; The routine Gestalt will call to tell where my install routines are
  78. ;
  79. MyGestaltHandler
  80.         link    A6,#0
  81.         move.l    8(A6),A0    ;return the proper response
  82.         lea        Myfunction,A1
  83.         move.l    A1,(A0)
  84.         clr.w    16(A6)
  85.         unlk    A6
  86.         move.l    (SP)+,A0
  87.         adda.l    #8,SP
  88.         jmp    (A0)
  89. ;
  90. ; This is called by GetNextEvent, with the event mask in D0, and the pointer to the
  91. ;    event record in A1.  We'll look for our HotKey here.
  92. ;
  93. gfThepsn    equ        -8
  94. gfTheName    equ        gfThepsn-32
  95. gfTheInfo    equ        gfTheName-processAppSpec-4
  96.  
  97. myGNEFilter
  98.             link    A6,#gfTheInfo
  99.             movem.l    D0-D5/A0-A3,-(SP)
  100.             move.l    A1,A3
  101.             move.l    D0,D4
  102.         
  103.             lea    TheItemsTbl,A2    ;get the pointer to the first pointer
  104.             moveq    #TblMax-1,D5
  105. @TheLoop    tst.l    TblProc(A2)        ;skip any blanks
  106.             beq.s    @NextLoop
  107.             
  108.             move.l    #processAppSpec+4,gfTheInfo(A6)
  109.             clr.l    gfTheInfo+processAppSpec(A6)
  110.             lea        gfTheName(A6),A0
  111.             move.l    A0,gfTheInfo+processName(A6)
  112.         
  113.             clr.w    -(SP)            ;see if we can get info on this process
  114.             pea        TblPSN(A2)
  115.             pea        gfTheInfo(A6)
  116.             _GetProcessInformation
  117.             tst.w    (SP)+
  118.             beq.s    @GotOne
  119.             clr.l    TblProc(A2)        ;bad entry, app    must've crashed.  Kill this entry
  120.             clr.l    TblRef(A2)
  121.             clr.l    TblPSN(A2)
  122.             clr.l    TblPSN+4(A2)
  123.             bra.s    @NextLoop
  124. @GotOne    
  125.             clr.w    -(SP)            ;OK, call this routine
  126.             move.l    A3,-(SP)
  127.             move.l    TblRef(A2),-(SP)
  128.             move.l    TblProc(A2),A0
  129.             jsr        (A0)
  130.             tst.w    (SP)+            ;if returned true, he handled it
  131.             bne.s    @CallTheLast
  132. @NextLoop    adda.l    #TblSize,A2
  133.             dbra    D5,@TheLoop
  134. @CallTheLast
  135.             movem.l    (SP)+,D0-D5/A0-A3
  136.             unlk    A6
  137.         
  138.             move.l    OldHook, A0
  139.             jmp        (A0)
  140. ;
  141. ;    pascal void RegisterMe(short theAction, procptr theproc, long refcon);
  142. ;        1, Register.  Add an entry to the table with procptr, also keeping the processserialnumber
  143. ;        2, Dispose.  Remove any entry with the current process, theproc is ignored
  144. ;
  145. myftheRefcon    equ    8
  146. myftheProc        equ    myftheRefcon+4
  147. myftheAction    equ    myftheProc+4
  148. myfThepsn    equ        -8
  149. myfTheBool    equ    myfThepsn-2;
  150.  
  151. Myfunction    link    A6,#myfTheBool
  152.             movem.l    D2-D5/A2,-(SP)
  153.             
  154.             clr.l    myfThepsn(A6)        ;-8(A6) has our process serial number
  155.             clr.l    myfThepsn+4(A6)
  156.         
  157.             clr.w    -(SP)        ;see if we can get the next process
  158.             pea        myfThepsn(A6)
  159.             _GetCurrentProcess
  160.             tst.w    (SP)+
  161.             
  162.             cmpi.w    #1,myftheAction(A6)    ;if it's register, do it
  163.             beq        DoTheRegister
  164.             cmpi.w    #2,myftheAction(A6)    ;if it's dispose, do it
  165.             beq        DoTheDispose
  166.  
  167.             bra    ReturnfromFunc
  168.             
  169. DoTheRegister
  170.             lea    TheItemsTbl,A2    ;get the pointer to the first pointer
  171.             moveq    #TblMax-1,D5
  172. @TheLoop    tst.l    TblProc(A2)        ;looking for an empty spot
  173.             bne.s    @NextLoop
  174.             move.l    myftheProc(A6),TblProc(A2)    ;found one.  Fill it out.
  175.             move.l    myftheRefcon(A6),TblRef(A2)
  176.             move.l    myfThepsn(A6),TblPSN(A2)
  177.             move.l    myfThepsn+4(A6), TblPSN+4(A2);
  178.             bra        ReturnFromFunc
  179. @NextLoop    adda.l    #TblSize,A2
  180.             dbra    D5,@TheLoop
  181.             bra        ReturnFromFunc
  182.  
  183. DoTheDispose
  184.             lea    TheItemsTbl,A2    ;get the pointer to the first pointer
  185.             moveq    #TblMax-1,D5
  186. @TheLoop    
  187.             clr.w    -(SP)            ;call _SameProcess
  188.             pea        myfThepsn(A6)
  189.             pea        TblPSN(A2)
  190.             pea        myfTheBool(A6)
  191.             clr.w    myfTheBool(A6)
  192.             _SameProcess
  193.             tst.w    (SP)+
  194.             tst.w    myfTheBool(A6)
  195.             beq.s    @NextLoop
  196.             Clr.l    TblProc(A2)        ;disposing, so get rid of it
  197.             clr.l    TblRef(A2)
  198.             clr.l    TblPSN(A2)
  199.             Clr.l    TblPSN+4(A2)
  200. @NextLoop    adda.l    #TblSize,A2
  201.             dbra    D5,@TheLoop
  202.             ;bra    ReturnFromFunc
  203.  
  204. ReturnFromFunc
  205.             movem.l    (SP)+,D2-D5/A2
  206.             unlk    A6
  207.             
  208.             move.l    (SP)+,A0                ;clean up the stack
  209.             adda.l    #10,SP
  210.             jmp        (A0)
  211.  
  212. OldHook            dc.l    0
  213. TheInstallProc    dc.l    0
  214. TheItemsTbl    dcb.b    TblSpace,0
  215.  
  216.         end
  217.